﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KeaoBase;

namespace KeaoMDS.Auth
{
    public partial class RuanJianShouQuan : BaseForm
    {
        private bool m_ShouQuan = false;
        public string m_ZhuCeMa = string.Empty;
        public RuanJianShouQuan(bool IsShouQuan)
        {
            InitializeComponent();
            m_ShouQuan = IsShouQuan;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_ShouQuan)
                {
                    //授权
                    if (!string.IsNullOrEmpty(txt_shouquanma.Text))
                    {
                        string str = KeaoUtils.Decrypt(txt_shouquanma.Text);
                        if (str == string.Format("Keao{0}", DateTime.Today.ToString("yyyy-MM-dd 00:00:00")))
                        {

                            DataTable row = KeaoUtils._DB.GetDataTableByCondition("tbl_zhuce");
                            if (row == null)
                            {
                                return;
                            }
                            TableRow editRow = new TableRow("tbl_zhuce", string.Format("{0}", row.Rows[0]["id"]), DBCtl.修改);
                            editRow.DataCols.Add(new TableCol() { ColName = "cpuid", ValueMember = KeaoUtils.getCpuID(), ValueType = DataValueCommonType.字符串 });
                            if (KeaoUtils._DB.SaveTableRows(editRow) > 0)
                            {
                                DialogResult = DialogResult.Yes;
                            }
                            else
                            {
                                DialogResult = DialogResult.No;
                            }
                        }
                        else
                        {
                            DialogResult = DialogResult.No;
                        }
                    }
                    else
                    {
                        KeaoUtils.ShowWarnMessage("请输入授权码，授权码当天有效。");
                    }
                }
                else
                {
                    //注册
                    m_ZhuCeMa = txt_shouquanma.Text;
                    DialogResult= DialogResult.Yes;
                }
            }
            catch (Exception err)
            {
                KeaoUtils.LogTxt(string.Format("{0}_软件注册异常。", err.Message));
            }
        }

        private void RuanJianShouQuan_Load(object sender, EventArgs e)
        {
            if (!m_ShouQuan)
            {
                this.Text = "软件注册";
                label8.Text = "注册码";
                button1.Text = "注册";

            }
        }
    }
}
